﻿#region references
using System;
using System.Web;
using System.IO;
#endregion

namespace IcaGames.Logging
{
    /*
     * Class that holds common functions used for the logging system.
     * 
     * @author
     * Rick Oonk
     * 
     * @version
     * 1.0
     * 
     * @update
     * 20-11-2009 by Rick Oonk.
     * Created Class and added attributes and standard functions. 
     */
    public class Log
    {
        #region private attributes
        private static string logFormat;
        private static string errorTime;
        #endregion

        public Log()
        {
            /* Create the DateTime stamp and put in standard data */
            logFormat = DateTime.Now.ToString() + " ***** ";
            string year = DateTime.Now.Year.ToString();
            string month = DateTime.Now.Month.ToString();
            string day = DateTime.Now.Day.ToString();
            errorTime = "errorlog" + day + month + year + ".txt";
        }

        /*
         * Function to create an error log file and save it to disk.
         * 
         * @param
         * msg: The error message to save to the file.
         */
        public static void CreateLog(string msg, string className)
        {
            /* Create the log and save it to disk */
            Log logFile = new Log();
            string path = HttpContext.Current.Server.MapPath(@"~\logs\");

            /* Put the new error message into the logfile */
            StreamWriter sw = new StreamWriter(path + errorTime, true);
            sw.WriteLine(logFormat + "[" + className + "] ***** " + msg);
            sw.Flush();
            sw.Close();
        }
    }
}
